/*
 * Copyright 2016 Huawei Technologies Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openo.sdno.mss.dao.constant;

/**
 * This class defines several Inventory SQL States.<br>
 * <p>
 * </p>
 * 
 * @author
 * @version SDNO 0.5 May 19, 2016
 */
public enum InvSqlState {

    /**
     * Attempt to insert duplicate key row
     */
    INSERT_DUPLICATE_KEY(2601, 23000),

    /**
     * dead lock,need to retry
     */
    DEAD_LOCK(1205, 1205),

    /**
     * unknown state
     */
    UNKNOWN(-1, -1);

    /**
     * status code of sybase
     */
    private int sybaseCode;

    /**
     * status code of SQL server
     */
    private int sqlserverCode;

    /**
     * Constructor<br>
     * <p>
     * </p>
     * 
     * @since SDNO 0.5
     * @param sybaseCode status code of sybase
     * @param sqlserverCode status code of SQL server
     */
    private InvSqlState(int sybaseCode, int sqlserverCode) {

        this.sybaseCode = sybaseCode;
        this.sqlserverCode = sqlserverCode;
    }

    /**
     * Check whether current status code matches stateCode.<br>
     * 
     * @param stateCode stateCode input
     * @return true if current status code matches stateCode, false otherwise
     * @since SDNO 0.5
     */
    public boolean matches(int stateCode) {
        switch(InvDbType.get()) {
            case SYBASE:
                return sybaseCode == stateCode;
            case SQLSERVER:
                return sqlserverCode == stateCode;
            default:
                return false;
        }
    }
}
